package com.cn.dao;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.cn.entity.DepartmentDetail;
import com.cn.entity.NewsDetail;



/*
 * 新闻详情类数据操作
 */
public class NewsDetailDao extends BaseDao {
	private NewsDetail newsDetail=null;

	/**
	 * 
	 * @param news 新闻详情对象
	 * @return 
	 */
	 
	public int  saveDepartment(NewsDetail newsDetail) {
		int count =0;
			con = this.getCon();
			 String sql ="insert into news_detail values(?,?)";
			try {
				psta = con.prepareStatement(sql);
				psta.setInt(1, newsDetail.getId());
				psta.setString(2, newsDetail.getTag());
				psta.setInt(3, newsDetail.getNid());
				psta.setString(4, newsDetail.getTitle());
				psta.setInt(5,newsDetail.getUptime());
				psta.setInt(6, newsDetail.getHits());
				psta.setString(7, newsDetail.getContent());
				psta.setString(8, newsDetail.getSource());
				psta.setInt(9, newsDetail.getImgmode());
				count = psta.executeUpdate();
			} catch (Exception e) {
				e.printStackTrace();
			}finally{
				this.closeAll();
			}
			
			return count;
		}
	
	/**
	 * 查询相应新闻信息标题
	 * @return 返回所有新闻集合
	 */
	public NewsDetail findNewsDetail(int id) {
		newsDetail = new NewsDetail();
		con = this.getCon();
		String sql ="select * from news_detail where nid="+id;
		try {
			psta = con.prepareStatement(sql);
			rst = psta.executeQuery();
			while (rst.next()) {
				newsDetail.setId(rst.getInt("id"));
				newsDetail.setTag(rst.getString("tag"));
				newsDetail.setNid(rst.getInt("nid"));
				newsDetail.setTitle(rst.getString("title"));
				newsDetail.setUptime(rst.getInt("uptime"));
				newsDetail.setHits(rst.getInt("hits"));
				newsDetail.setContent(rst.getString("content"));
				newsDetail.setSource(rst.getString("source"));
				newsDetail.setImgmode(rst.getInt("imgmode"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			this.closeAll();
		}
		
		return newsDetail;
	}
	/**
	 * 测试
	 * @param args
	 */
	public static void main(String[] args) {
		NewsDetailDao dt=new NewsDetailDao();
		NewsDetail dmDetail = dt.findNewsDetail(8976);
		System.out.println(dmDetail.getClass());
		System.out.println(dmDetail.getTitle());
	}

}
